package algos;

import java.util.Iterator;
import java.util.List;

public class GeneralLinearInterpolation extends EstimationFunction{

    private List<Function<Integer, Double>> coef;
    private List<EstimationFunction> estimators;


    public GeneralLinearInterpolation(List<Function<Integer, Double>> coef, List<EstimationFunction> estimators) {
        super();
        this.coef = coef;
        this.estimators = estimators;
        //TODO: check size;
    }

    @Override
    public double p(int wordIndex) {
        Iterator<EstimationFunction> iter = estimators.iterator();
        double result = 0;
        for (Function<Integer, Double> lambdas: coef) {
            result += lambdas.f(wordIndex) * iter.next().p(wordIndex);
        }
        return result;
    }
}
